package com.thinkgem.jeesite.modules.sys.utils;

import com.thinkgem.jeesite.common.utils.CacheUtils;
import com.thinkgem.jeesite.common.utils.SpringContextHolder;
import com.thinkgem.jeesite.modules.book.dao.BookPublisherDao;
import com.thinkgem.jeesite.modules.book.entity.BkPublisher;

import java.util.List;

/**
 * PublisherUtils
 * Created by aulbrother on 2015/12/21.
 */
public class PublisherUtils{
    private static BookPublisherDao publisherDao = SpringContextHolder.getBean(BookPublisherDao.class);
    public static final String CACHE_PUBLISHER_MAP = "publisherMap";

    public static List<BkPublisher> getPublisherList(){
        @SuppressWarnings("unchecked")
        List<BkPublisher> dictList = (List<BkPublisher>)CacheUtils.get(CACHE_PUBLISHER_MAP);
        if(dictList == null){
            dictList = publisherDao.findAll();
            CacheUtils.put(CACHE_PUBLISHER_MAP, dictList);
        }
        return dictList;
    }

    public static void refreshPublisher(){
        List<BkPublisher> dictList = publisherDao.findAll();
        CacheUtils.put(CACHE_PUBLISHER_MAP, dictList);
    }
}
